package com.team2.outpatient_sys.web;

import com.team2.outpatient_sys.pojo.DepartmentAndDoctors;
import com.team2.outpatient_sys.pojo.Doctor;
import com.team2.outpatient_sys.pojo.Result;
import com.team2.outpatient_sys.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dept")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    /**
     * 处理通过科室id查询某一科室的信息及该科室下所有医生信息的集合的请求的Controller方法
     * @param deptId 查询的科室的id
     * @return 响应内容，查询请求的结果，data中封装了查询结果的数据
     */
    @GetMapping("/andDoctors/{deptId}")
    public Result getDeptAndDoctors(@PathVariable Integer deptId) {
        DepartmentAndDoctors departmentAndDoctors = departmentService.getDeptAndDoctors(deptId);

        Result result = new Result();
        if (departmentAndDoctors == null) {
            result.setCode(500);
            result.setMsg("通过id查询科室及科室下所有的医生信息时发生异常");
        } else {
            result.setCode(200);
            result.setMsg("通过id查询科室及科室下所有的医生信息成功");
            result.setData(departmentAndDoctors);
        }

        return result;
    }

    /**
     * 处理通过科室id查询某一科室下所有医生信息的集合的请求的Controller方法
     * @param deptId 查询的科室的id
     * @return 响应内容，查询请求的结果，data中封装了查询结果的数据
     */
    @GetMapping("/doctors/{deptId}")
    public Result getDoctors(@PathVariable Integer deptId) {
        List<Doctor> doctors = departmentService.getDoctors(deptId);

        Result result = new Result();
        if (doctors == null) {
            result.setCode(500);
            result.setMsg("通过id查询科室下所有的医生信息时发生异常");
        } else {
            result.setCode(200);
            result.setMsg("通过id查询某科室下所有的医生信息成功");
            result.setData(doctors);
        }

        return result;
    }
}
